package com.shy.example.hystrix.controller;

import com.shy.example.hystrix.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("dept")
@Slf4j
public class DeptController {

    @Resource
    private DeptService deptService;

    @GetMapping("hystrix/ok/{id}")
    public String deptInfo_Ok(@PathVariable("id") Integer id){
        String result = deptService.deptInfo_Ok(id);
        log.info("result:" + result);
        return result;
    }

    @GetMapping("hystrix/timeout/{id}")
    public String deptInfo_Timeout(@PathVariable("id") Integer id){
        String result = deptService.deptInfo_Timeout(id);
        log.info("result: " + result);
        return result;
    }

    @GetMapping("hystrix/circuit/{id}")
    public String deptCircuitBreaker(@PathVariable("id") Integer id){
        String result = deptService.deptCircuitBreaker(id);
        log.info("result: {}", result);
        return result;
    }
}
